package com.zx.练习题._2022面试题;

import java.util.Arrays;
import java.util.regex.Pattern;

/**
 * (java8) 用 stream + lambda 将以下数组中的数字过滤出来，转换为 Integer 类型，并按照升序打印 ["abc", "3", "def", "2", "1"]
 */
public class Demo7 {

    private static final Pattern pattern = Pattern.compile("^[0-9]*$");
    ;

    public static void main(String[] args) {
        String[] ss = {"abc", "3", "def", "2", "1"};
        Arrays.stream(ss)
                .filter(Demo7::isNum)
                .map(Integer::parseInt)
                .sorted()
                .forEach(System.out::println);
    }

    private static boolean isNum(String str) {
        return pattern.matcher(str).find();
    }

}
